package utils;

import model.ProxyEvent;

/**
 * facciamo finta che non esista, così si dorme meglio
 * @author koelio
 *
 */
public class Orderer {

	private ProxyEvent event;

	public void sortEvents() {

		for (int i = 0; i < event.getEvents().size(); i++) {
			for (int j = 0; j < event.getEvents().size() - 1; j++) {

				if (event.getDates().get(j) > event.getDates().get(j + 1)) {
					int k = event.getDates().get(j);
					event.getDates().set(j, event.getDates().get(j + 1));
					event.getDates().set(j + 1, k);

					String l = event.getPlaces().get(j);
					event.getPlaces().set(j, event.getPlaces().get(j + 1));
					event.getPlaces().set(j + 1, l);

					String m = event.getEvents().get(j);
					event.getEvents().set(j, event.getEvents().get(j + 1));
					event.getEvents().set(j + 1, m);

				} else if (event.getDates().get(j)
						.equals(event.getDates().get(j + 1))) {

					System.out.println("ano");

					for (int j2 = 0; j2 < event.getEvents().size() - 2; j2++) {
						Integer alf = event
								.getPlaces()
								.get(j)
								.compareToIgnoreCase(
										event.getPlaces().get(j + 1));
						if (alf > 0) {

							String n = event.getPlaces().get(j);
							event.getPlaces().set(j,
									event.getPlaces().get(j + 1));
							event.getPlaces().set(j + 1, n);

							String o = event.getEvents().get(j);
							event.getEvents().set(j,
									event.getEvents().get(j + 1));
							event.getEvents().set(j + 1, o);

							int p = event.getDates().get(j);
							event.getDates()
									.set(j, event.getDates().get(j + 1));
							event.getDates().set(j + 1, p);

						} else if (alf.equals(0)) {

							for (int k = 0; k < event.getEvents().size() - 1; k++) {
								int alf2 = event
										.getEvents()
										.get(j)
										.compareToIgnoreCase(
												event.getEvents().get(j + 1));
								if (alf2 > 0) {
									String p = event.getEvents().get(j);
									event.getEvents().set(j,
											event.getEvents().get(j + 1));
									event.getEvents().set(j + 1, p);

									String n = event.getPlaces().get(j);
									event.getPlaces().set(j,
											event.getPlaces().get(j + 1));
									event.getPlaces().set(j + 1, n);

									int q = event.getDates().get(j);
									event.getDates().set(j,
											event.getDates().get(j + 1));
									event.getDates().set(j + 1, q);

								}// end last if
							}//
						}
					}
				}

			}

		}

	}

	public void setEvent(ProxyEvent event) {
		this.event = event;
	}

}